#!/usr/bin/env bash

# Copyright 2007 Ryan Phillips.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

die() {
    echo $1
    exit 1
}

usage() {
    echo "build_release.sh 0.0.1"
    exit 1
}

# Check for command line arguments
[[ "$1" == "" ]] && usage

VER=$1
REPO=https://libxblf.googlecode.com/svn
PKGNAME=libxblf
PKGNAMELONG="$PKGNAME-$VER"
TMPPKGDIR=../$PKGNAMELONG

# tag the release
echo "Creating tag $VER" 
svn copy -m "created release tag $VER" $REPO/trunk $REPO/tags/$VER || die "Could not create tag"

# export to directory
echo "Exporting directory"
svn export . $TMPPKGDIR || dir "svn export failed"

# create version file
echo "Creating version file"
echo $VER > $TMPPKGDIR/VERSION

cd ..

# create tarball
echo "Creating tarball"
tar zcvf $PKGNAMELONG.tar.gz $PKGNAMELONG

# create zip
echo "Creating zip"
zip -r $PKGNAMELONG.zip $PKGNAMELONG

# cleanup
echo "Cleanup"
rm -rf $PKGNAMELONG
